﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _ajax : JumbotCms.API.AdminCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            ChannelId = Str2Str(q("ccid"));
            Admin_Load("", "json", true);
            this._operType = q("oper");
            switch (this._operType)
            {
                case "ajaxMove2Special":
                    ajaxMove2Special();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }

        private void DefaultResponse()
        {
            this._response = JsonResult(0, "未知操作");
        }
        /// <summary>
        /// 加入专题
        /// </summary>
        private void ajaxMove2Special()
        {
            string tosid = f("tosid");
            string ids = f("ids");
            string _contentid = string.Empty;
            string _title = string.Empty;
            string _channelid = string.Empty;
            doh.Reset();
            doh.SqlCmd = "SELECT [Id],[Title],[ChannelId] FROM [jcms_module_" + ChannelType + "] WHERE [ChannelId]=" + ChannelId + " AND id in (" + ids + ")";
            DataTable dt = doh.GetDataTable();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                _contentid = dt.Rows[i]["Id"].ToString();
                _title = dt.Rows[i]["Title"].ToString();
                _channelid = dt.Rows[i]["ChannelId"].ToString();
                doh.Reset();
                doh.ConditionExpress = "sid=@sid and contentid=@contentid and channelid=@channelid";
                doh.AddConditionParameter("@sid", tosid);
                doh.AddConditionParameter("@contentid", _contentid);
                doh.AddConditionParameter("@channelid", _channelid);
                if(!doh.Exist("jcms_normal_specialcontent"))
                {
                    doh.Reset();
                    doh.AddFieldItem("Title",_title);
                    doh.AddFieldItem("sId", tosid);
                    doh.AddFieldItem("ChannelId", _channelid);
                    doh.AddFieldItem("ContentId", _contentid);
                    doh.Insert("jcms_normal_specialcontent");
                }
            }
            this._response = JsonResult(1, "操作成功");
        }
    }
}